package com.yenlien.traceyun.business.controller;

import com.yenlien.traceyun.business.entity.Feedback;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.business.service.FeedbackService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by LiuSha on 2020/7/24.
 */
@RestController
@RequestMapping(value = "/feedback")
public class FeedbackController extends BaseController {

    @Autowired
    private FeedbackService feedbackService;

    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody Feedback feedback) {
        feedback.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        return buildPage(feedbackService.findByList(feedback));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Feedback feedback) {
        feedback.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        feedbackService.save(feedback);
        return success("success");
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Object delete(@PathVariable String id) {
        feedbackService.delete(id);
        return success("success");
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object update(@RequestBody Feedback feedback) {
        feedbackService.update(feedback);
        return success("success");
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable String id) {
        return success(feedbackService.findById(id));
    }

}
